package com.jd.myaaaccount.util;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class JsonHelper {
	private static Gson gson = null;

	private static void iniGson() {
		if (gson == null) {
			gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss")
					.create();
		}
	}

	/**
	 * 将json格式转换成指定对象
	 * 
	 * @param json
	 * @param t
	 * @return
	 */
	public static <T> T getObject(String json, Class<T> t) {
		iniGson();
		return gson.fromJson(json, t);
	}

	public static String getString(Object obj) {
		iniGson();
		return gson.toJson(obj);
	}
}
